Portfolio Lens
Overview
The Portfolio Lens contract is a collection of view-only helper functions to
fetch position, asset and debt data. It also provides a helper function to
predict the address for new positions deployed using CREATE2.
State Variables
POOL
Address to the protocol's pool instance
Pool public immutable POOL;
RISK_ENGINE
Address to the protocol's risk engine instance
RiskEngine public immutable RISK_ENGINE;
POSITION_MANAGER
Address to the protocol's position manager instance
PositionManager public immutable POSITION_MANAGER;
Functions
constructor
constructor(address pool, address riskEngine, address positionManager);
Parameters
| Name | Type | Description | 
|---|---|---|
| pool | address | Address to the protocol's pool instance | 
| riskEngine | address | Address to the protocol's risk engine instance | 
| positionManager | address | Address to the protocol's position manager instance | 
getPortfolioData
Fetch current state for multiple positions at once
function getPortfolioData(address[] calldata positions) public view returns (PortfolioData memory portfolioData);
Parameters
| Name | Type | Description | 
|---|---|---|
| positions | address[] | Array of position addresses | 
Returns
| Name | Type | Description | 
|---|---|---|
| portfolioData | PortfolioData | Array of current position data for each given position | 
getPositionData
Fetch current state for a given position
function getPositionData(address position) public view returns (PositionData memory positionData);
Parameters
| Name | Type | Description | 
|---|---|---|
| position | address | Address of the position | 
Returns
| Name | Type | Description | 
|---|---|---|
| positionData | PositionData | Current position data for the given position | 
getAssetData
Fetch data for all assets currently held by a position
Could return values with zero amount if AddToken / RemoveToken has not been called
function getAssetData(address position) public view returns (AssetData[] memory assetData);
Parameters
| Name | Type | Description | 
|---|---|---|
| position | address | Address of the position | 
Returns
| Name | Type | Description | 
|---|---|---|
| assetData | AssetData[] | List of data for assets currently held by the given position | 
getDebtData
Fetch data for all active debt associated a given position
function getDebtData(address position) public view returns (DebtData[] memory debtData);
Parameters
| Name | Type | Description | 
|---|---|---|
| position | address | Address of the position | 
Returns
| Name | Type | Description | 
|---|---|---|
| debtData | DebtData[] | List of pool-wise debt data currently owed by the given position | 
predictAddress
Utility function to predict the CREATE2 address for a new position
function predictAddress(address owner, bytes32 salt) external view returns (address newPosition, bool available);
Parameters
| Name | Type | Description | 
|---|---|---|
| owner | address | Address of the new position owner | 
| salt | bytes32 | CREATE2 salt for the new position | 
Returns
| Name | Type | Description | 
|---|---|---|
| newPosition | address | Predicted address for the new position | 
| available | bool | Boolean which is false if the predicted position address already has code deployed to it | 
Structs
PortfolioData
Container for data associated with multiple positions
struct PortfolioData {
    PositionData[] positions;
}
PositionData
Container for data associated with a single position
struct PositionData {
    address position;
    address owner;
    AssetData[] assets;
    DebtData[] debts;
}
AssetData
Generic container for position asset data
struct AssetData {
    address asset;
    uint256 amount;
    uint256 valueInEth;
}
DebtData
Generic container for position debt data
struct DebtData {
    uint256 poolId;
    address asset;
    uint256 amount;
    uint256 valueInEth;
    uint256 interestRate;
}